package club.ruanx.auth.service;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author 阮胜
 * @date 2018/8/4 16:35
 */
@Component
@Qualifier("adminDetailService")
public class AdminDetailServiceImpl implements UserDetailsService {


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (!"rose".equals(username)) {
            throw new UsernameNotFoundException("找不到用户");
        }
        return new org.springframework.security.core.userdetails.User("rose", "rosePwd"
                , AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ADMIN"));
    }
}
